<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
    <title>Mixins Option Demo</title>
</head>

<body>
    <h1>Mixins</h1>
    <hr>
    <div id="app">
        <p>num:{{ num }}</p>
        <P>
            <button @click="add">增加数量</button>
        </P>
    </div>
    <script type="text/javascript">
        //额外临时加入时，用于显示日志
        var addLog = {
            updated: function () {
                console.log("数据发生变化,变化成" + this.num + ".");
            }
        }
        Vue.mixin({
            updated: function () {
                console.log("我是全局的混入")
            }
        })
        var app = new Vue({
            el: '#app',
            data: {
                num: 1
            },
            methods: {
                add: function () {
                    this.num++;
                }
            },
            updated() {
                console.log("我是原生的update")
            },
            mixins: [addLog]//混入
        })
    </script>
</body>

</html>